package com.example.f8399.testdemo.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by f8399 on 2018/7/6.
 */

public class RectView extends View {
    private Paint mPaint;

    public RectView(Context context) {
        super(context);
        initView();
    }

    private void initView() {
        mPaint = new Paint();
    }

    public RectView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public RectView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        mPaint.setStrokeWidth(5f);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(Color.RED);
        mPaint.setAlpha(20);

        Rect rect = new Rect(200, 300, 400, 500);
        canvas.drawRect(rect, mPaint);

    }
}
